//
//  ViewController.swift
//  ZJSwiftKit
//
//  Created by zyx on 02/15/2023.
//  Copyright (c) 2023 zyx. All rights reserved.
//

import UIKit
import ZJSwiftKit

class ViewController: UIViewController {

    @IBOutlet weak var testLabel: UILabel!
    @IBOutlet weak var screenshotView: UIView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        
        // MARK: - XIB 加载view
        if let yellowView = TestYellowView.zj.loadFromNib(named: "\(TestYellowView.self)", bundle: nil) {
            yellowView.frame = CGRect.init(x: 100, y: 100, width: 100, height: 100)
            view.addSubview(yellowView)
            
            let brownView = UIView.init()
            brownView.backgroundColor = .brown
            // 必须先添加到父视图才能调用此方法
            yellowView.addSubview(brownView)
            brownView.zj.fillToSuperview(contentEdgeInsets: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
            
        }
//        screenshotView.zj.addRoundCorners([.topLeft, .topRight], radius: 15)
        
        screenshotView.zj.addDashLine(withPosition: [.top], color: UIColor.red, width: 4, length: 4, spacing: 2)
        screenshotView.zj.addDotLine(withPosition: [.left], color: UIColor.black)
        screenshotView.zj.addDotLine(withPosition: [.right], color: UIColor.black, width: 8, spacing: 4)
        screenshotView.zj.addLine(withPosition: [.bottom], color: UIColor.red)
        
        let dashLine = UIView.zj.dashLine(withColor: .red, horizontal: true)
        
        screenshotView.addSubview(dashLine)
        dashLine.frame = CGRect(x: 10, y: 30, width: 200, height: 2)
    
        let dotLine = UIView.zj.dotLine(withColor: .red, spacing: 10)
        
        screenshotView.addSubview(dotLine)
        dotLine.frame = CGRect(x: 10, y: 50, width: 200, height: 5)
        
        
        print("是否包含Emoji", "🤔".zj.containEmoji )
        
        print("邮箱验证: ", "8457099@qq.com".zj.isValidEmail)
        
        
        
        // MARK: - JSON
        
        let jsonDictString = "{\"name\":\"设计部\",\"id\":\"61679315e616fd0001d90327\"}"
        
        let jsonArrayString = "[\n{\n\"name\":\"zyx\",\n\"content\":\"zzzzzzzzzzzzz\"\n}\n]"
        
        if  let array = jsonArrayString.zj.jsonToArray() {
            print(array)
            
            var str = array.zj.toJsonString()
            print(str)
            str += "zzz"
            print(str)
            
        }
        
        if let dict = jsonDictString.zj.jsonToDictionary() {
            print(dict)
            print(dict["id"] as! String )
            
            print("dict to jsonString: \(dict.zj.toJsonString())")
            
        }
        
        let string = "abcdefghijk"
        print(string.zj.replace(in: "a", with: "1"))
        print(string.zj.replace(in: 0, with: "1"))
        print(string.zj.replace(in: 0...0, with: "1"))
        print(string.zj.replace(in: 0..<1, with: "1"))
        print(string.zj.replace(in: ...0, with: "1"))
        print(string.zj.replace(in: ..<1, with: "1"))
        
        // MARK: string to image
        navigationItem.titleView = UIImageView.init(image: "testIcon".zj.toImage())
        testLabel.font = 6.zj.customFont(with: .HelveticaNeue(.blod))
        
        
        class ZJDynamicClass: ZJDynamicProtocol {
             var a: String = "123"
             var b: Int = 0
         }
        let dataModel = ZJDynamicClass()
        dataModel.zjDy.a = "abc"
        print(dataModel.zjDy.a)
        dataModel.zjDy.b = 100
        print(dataModel.zjDy.b)
        
        dataModel.zjDy.cccccc = "tempAbc"
        print(dataModel.zjDy.cccccc as Any)
        
    }
    // MARK: - 视图截图
    @IBAction func makeScrrenshot(_ sender: Any) {
        let vc = ScreenshotViewController.init()
        vc.image = screenshotView.zj.screenshot
        navigationController?.pushViewController(vc, animated: true)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

